import e from "./mat3";
import t from "./vec2";
import n from "./align_mode";

class ScaleMode {
  static align(e, r, i, s, o) {
    let u = new t();
    return (
      (o & n.LEFT) != 0
        ? (u.x = 0)
        : (o & n.CENTER) != 0
        ? (u.x = Math.round(i / 2 - e / 2))
        : (o & n.RIGHT) != 0 && (u.x = Math.round(i - e)),
      (o & n.TOP) != 0
        ? (u.y = 0)
        : (o & n.MIDDLE) != 0
        ? (u.y = Math.round(s / 2 - r / 2))
        : (o & n.BOTTOM) != 0 && (u.y = Math.round(s - r)),
      u
    );
  }
  static noScale(t, n, i, s, o) {
    let u = new e(),
      a = this.align(t, n, i, s, o);
    return (u.tx = a.x), (u.ty = a.y), u;
  }
  static showAll(t, n, i, s, o) {
    let u = Math.min(i / t, s / n),
      a = Math.round(t * u),
      f = Math.round(n * u),
      l = new e();
    (l.a = a / t), (l.d = f / n);
    let c = this.align(a, f, i, s, o);
    return (l.tx = c.x), (l.ty = c.y), l;
  }
  static noBorder(t, n, i, s, o) {
    let u = Math.max(i / t, s / n),
      a = Math.round(t * u),
      f = Math.round(n * u),
      l = new e();
    (l.a = a / t), (l.d = f / n);
    let c = this.align(a, f, i, s, o);
    return (l.tx = c.x), (l.ty = c.y), l;
  }
  static extraFit(t, n, r, i) {
    let s = new e();
    return (s.a = r / t), (s.d = i / n), s;
  }
  static fitWidth(t, n, i, s, o) {
    let u = i / t,
      a = Math.round(t * u),
      f = Math.round(n * u),
      l = new e();
    (l.a = a / t), (l.d = f / n);
    let c = this.align(a, f, i, s, o);
    return (l.tx = c.x), (l.ty = c.y), l;
  }
  static fitHeight(t, n, i, s, o) {
    let u = s / n,
      a = Math.round(t * u),
      f = Math.round(n * u),
      l = new e();
    (l.a = a / t), (l.d = f / n);
    let c = this.align(a, f, i, s, o);
    return (l.tx = c.x), (l.ty = c.y), l;
  }
}

export default ScaleMode;
